/**
 *
 * @param table {Table}
 * @param auth {boolean} 接口是否需要鉴权
 * @param uninstall {boolean} 是否在生成代码时注释该方法，用于备用
 * @returns {string}
 */
const findCacheById = (table, auth = false, uninstall = false) => {
  const {
    idType,
    comment,
    isJpaModel,
    names: {TabName}
  } = table
  return `
    /**
     * ${comment} 按 ID 查询并缓存到redis
     *
     * @param id   {@link ${idType}} 数据ID
     * @return {@link ${TabName}} 实体对象
     */
     @Cacheable(cacheNames = I${TabName}Cache.CACHE_ROW_BY_ID, key = "#id", unless="#result == null") // 若使用缓存需要解开代码
     ${isJpaModel ? 'default' : 'public'} ${TabName} findCacheById(final ${idType} id){
         return findById(id).orElse(null);
     }
`.split('\n')
    .map(row => (uninstall ? '//' : '') + row)
    .join('\n')
}
export const findCacheByIdOpenInstall = table => findCacheById(table)
export const findCacheByIdOpenUninstall = table => findCacheById(table, false, true)

export const findCacheByIdAuthInstall = table => findCacheById(table, true, false)
export const findCacheByIdAuthUninstall = table => findCacheById(table, true, true)
